/*
 * Copyright 2011 Mark Davidson.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.dctmcommons;

import org.dctmcommons.impl.WorkflowHelper;

import org.junit.*;

import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;

import com.documentum.fc.client.IDfProcess;
import com.documentum.fc.common.DfDocbaseConstants;
import com.documentum.fc.common.DfException;

/**
 * Integration tests for {@link WorkflowHelper}.
 * @author Mark Davidson
 */
public class WorkflowHelperIT {

	/** The name of the quickflow workflow template. */
	private static final String QUICKFLOW_NAME = "dmSendToDistributionList";
	
	/** The {@link IWorkflowHeper} instance. */
	private IWorkflowHelper workflowHelper = null;
	
	/**
	 * Tests the factory method.
	 */
	@Test
	public void testGetInstance() {
		System.out.println(">>> testGetInstance");
		assertThat("Factory method returned null",
				   workflowHelper,
				   is(notNullValue()));
	}
	
	/**
	 * Tests retrieval of workflow templates - by name.
	 */
	@Test
	public void testGetWorkflowTemplateByName() throws DfException {
		System.out.println(">>> testGetWorkflowTemplateByName");
		final IDfProcess template = workflowHelper.getWorkflowTemplateByName(
											DctmCommonsTestUtil.getSession(),
											QUICKFLOW_NAME);
		assertThat("Unable to get workflow template by name: " + QUICKFLOW_NAME,
				   template,
				   is(notNullValue()));
		
		DctmCommonsTestUtil.releaseSession();
	}
	
	/**
	 * Tests retrieval of workflow templates - by qualification.
	 */
	@Test
	public void testGetWorkflowTemplateByQualification() throws DfException {
		System.out.println(">>> testGetWorkflowTemplateByQualification");
		final String qual = DfDocbaseConstants.OBJECT_NAME + " = '" +
								QUICKFLOW_NAME + "'";
		final IDfProcess template = workflowHelper
										.getWorkflowTemplateByQualification(
											DctmCommonsTestUtil.getSession(),
											qual);
		assertThat("Unable to get workflow template by qual: " + QUICKFLOW_NAME,
				   template,
				   is(notNullValue()));
		
		DctmCommonsTestUtil.releaseSession();
	}
	
	/**
	 * Setup routine.
	 */
	@Before
	public void before() throws DfException {
		workflowHelper = WorkflowHelper.getInstance();
	}
	
	/**
	 * Teardown routine.
	 */
	@After
	public void after() throws DfException {
	}
}
